import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Hashtable;


public class PhysicYearOfBirth {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		String physic = "/home/pjbarrio/workspace/PRDualRankReplication/physicNobelPrizeLaureates";
		
		BufferedReader br = new BufferedReader(new FileReader(new File(physic)));
		
		String line = br.readLine();

		ArrayList<String> physics = new ArrayList<String>();
		
		while (line!=null){
			
			physics.add(transform(line.trim()));
			
			line = br.readLine();
		}
		
		br.close();
		
		String birthyear = "/home/pjbarrio/workspace/PRDualRankReplication/NobelPrizeLaureatesYearOfBirth";
		
		BufferedReader br2 = new BufferedReader(new FileReader(new File(birthyear)));
		
		line = br2.readLine();
		
		Hashtable<String, Integer> birth = new Hashtable<String, Integer>();
		
		while (line != null){
			
			String[] split = line.split(" - ");
			
			birth.put(split[0].trim().toLowerCase(), Integer.valueOf(split[1].trim()));
			
			line = br2.readLine();
		}
		
		br2.close();
		
		System.setOut(new PrintStream(new File("/home/pjbarrio/workspace/PRDualRankReplication/physicNobelPrizeLaureatesYearOfBirth")));
		
		for (String physician : physics) {
			
			if (birth.get(physician.toLowerCase())==null){
				System.err.println(physician + " - " + birth.get(physician.toLowerCase()));
			} else {
				System.out.println(physician + " - " + birth.get(physician.toLowerCase()));
			}
		}
	}

	private static String transform(String trim) {
		
		String[] split = new String[2];
		
		int index = trim.indexOf(',');
		
		if (index == -1){
			return trim;
		}
		
		split[0] = trim.substring(0,index).trim();
		
		split[1] = trim.substring(index+1).trim();
		
		return split[1] + " " + split[0];
				
	}

}
